package 二叉树;

/**
 * @ClassName _669修剪二叉搜索树
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/10/5 19:24
 * Version 1.0
 **/
public class _669修剪二叉搜索树 {
    public TreeNode trimBST(TreeNode root, int low, int high) {
        if(root == null){
            return root;
        }
        if(root.val < low){
            root = root.right;
            root = trimBST(root,low,high);
        }else if (root.val > high){
            root = root.left;
            root = trimBST(root,low,high);
        }else {
            root.left = trimBST(root.left,low,high);
            root.right = trimBST(root.right,low,high);
        }
        return root;
    }
}
